<%@ page pageEncoding="UTF-8" %>
<jsp:useBean id="formBean" class="jp.co.technotree.apl.cmd.order.Tst1000Bean" scope="request" />
<%


%>
<html>
<head>



<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">

<link rel='stylesheet' type='text/css' href='../../common/css/order/odr1000.css' >


<!-- ITEM-DROPDOWN START -->
<link rel="stylesheet" href="../../common/js/dropdown/dropdown.css" type="text/css">
<script src="../../common/js/dropdown/dropdown.js" type="text/javascript"></script>
<!-- ITEM-DROPDOWN END -->



<script  TYPE="text/javascript">


// -------------------------------------------------------------------------
//<!-- ITEM-DROPDOWN START -->
var dropdown = null;

var inputDateTime = null;
var timerId = null;
var eventSrc={};
function text_onKeyUp(object,sender,evt){
	var value = sender.value;
	eventSrc.object = object;
	eventSrc.sender = sender;
	eventSrc.evt = evt;
	inputDateTime = new Date();
	//-----------------------------------------------
	//品番自動ハイフン「-」を付ける
	var chkLen=5;
	if(event.keyCode != 0008){
		//指定の桁以上ならスタート
		if(value.length>=chkLen){
			var hikaku = value.substring(chkLen, chkLen+1);
			if(hikaku != "-"){
				var frontValue = value.substring(0, chkLen);
				var backValue  = value.substring(chkLen, value.length);
				sender.value=frontValue+"-"+backValue;
			}
		}
	}
	//小文字を大文字へ
	sender.value = sender.value.toUpperCase();
	value = sender.value;
	//-----------------------------------------------
	if ( value.length >= 5 ){
		if ( evt.keyCode == 37 || evt.keyCode == 39 ){
			
		}else{
			if ( timerId == null ){
				// 連続送信防止
				timerId = window.setTimeout(function(){text_onTimeOut(object,sender,evt);},500);
			}
		}
	}
}

/**
 * 一定時間入力が止まった場合に動作
 */
function text_onTimeOut(object,sender,evt){
	var nowDateTime = new Date();
	var lngTime = (nowDateTime.getTime()-inputDateTime.getTime());
	if ( lngTime >= 1000 ){
		timerId = null;
		xmlRequest(object,sender,evt);
	}else{
		timerId = window.setTimeout(function(){text_onTimeOut(eventSrc.object,eventSrc.sender,eventSrc.evt);},500);
	}
}

/**
 * XML要求処理
 */
function xmlRequest(object,sender,evt){
	//alert(evt.keyCode);
	var table = document.getElementById("drop-contents");
	table.innerHTML="";
	
	var top = calculateOffsetTop(sender);
	var left = calculateOffsetLeft(sender);
	var height = sender.offsetHeight;
	var panel = document.getElementById("dropdown-panel");
	panel.style.top=top+height+"px";
	panel.style.left=left+"px";
	panel.style.display="block";
	
	var param="itemCd="+sender.value;
	
	try {
		var frm = document.main;
		var objs = frm["invCate"];
		if (objs[1].checked == true){
			//仮入出庫
			param += "&afterProc=1";
		}
	} catch (e) {
		
	}

	object.doXmlRequest(object,sender,param);
}


/**
 * リスト選択時コールバック処理
 */
function list_onSelect(object,sender,json){
	var panel = document.getElementById("dropdown-panel");
	panel.style.display="none";
	sender.focus();
	
	//----------
	var name=sender.name;
	var idx=name.substring(name.indexOf("[")+1,name.length-1);
	
	document.getElementById("sysItemCd["+idx+"]").value=json.sysitemcd;
	document.getElementById("itemCd["+idx+"]").value=json.itemcd;
	document.getElementById("itemName["+idx+"]").value=json.itemname;
	
	if (json.processname!=null) {
		document.getElementById("ProcessName["+idx+"]").innerHTML=json.processname;
	} else {
		document.getElementById("ProcessName["+idx+"]").innerHTML="";
	}
	if (json.vendorname!=null) {
		document.getElementById("VendorName["+idx+"]").innerHTML=json.vendorname;
	} else {
		document.getElementById("VendorName["+idx+"]").innerHTML="";
	}
	
	if (json.warehousecd2!=null) {
		document.getElementById("warehouseCd["+idx+"]").value=json.warehousecd2;
	} else {
		document.getElementById("warehouseCd["+idx+"]").value="";
	}
	
	
	
	
	if (json.processvendorcd!=null) {
//		document.getElementById("comment["+idx+"]").value=json.processvendorcd;
	} else {
//		document.getElementById("comment["+idx+"]").value="";
	}
}


function getElementsByClassName(parent,tagName,className,fullMatch){
	var i=0,j=0;
	var result = [], cnt = 0;
	var list = parent.getElementsByTagName(tagName);
	for ( i=0; i<list.length; i++ ){
		var name = list[i].className;
		if ( name ){
			var nameList = name.split(' ');
			for ( j=0; j<nameList.length; j++ ){
				if ( fullMatch ){
					if ( nameList[j] == className ){
						result[cnt++] = list[i];
					}
				}else{
					if ( nameList[j].indexOf(className) != -1 ){
						result[cnt++] = list[i];
					}
				}
			}
		}
	}
	return result;
}
function closeBtn(){
	var panel = document.getElementById("dropdown-panel");
	panel.style.display="none";
} 
//----------------------------------------------------------------------





function onInit(){
	var panel = document.getElementById("dropdown-panel");
	var input = document.getElementById("addTable");
	var targetList = getElementsByClassName(input,"input","item",true);
	
	dropdown = new CItemDropDownList(targetList,panel,"drop-contents");
	dropdown.setKeyUpEvent(text_onKeyUp);
	dropdown.setSelectEvent(list_onSelect);
	
	//
	dropdown.serverURL="../itm1099/itm1099";
	
}



//画面固定
//document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);


function nextPageJump(nextPage){
	mainForm = document.getElementById("F1");
	document.getElementById("nextPage").value = nextPage;
	mainForm.submit();
}
</script>


</head>

<body onLoad="onInit();">
<form name="main" id="F1" action="./tst1000" method="post" class="frmMain">

<table>
	<tr>
		<td>
			<table id="addTable" name="addTable" cellspacing="0" cellpadding="4" width="1050px" bordercolor="#C0C0C0" border="0" class="list">
			<tr>
				<td>aaaa</td>
				<td><input name="itemCd[0]"   class="item"     type="text" value=""   size="16" maxlength="20"></td>
			</tr>
			<tr>
				<td>bbbb</td>
				<td><input name="itemCd[1]"   class="item"     type="text" value=""   size="16" maxlength="20"></td>
			</tr>
			</table>
		</td>
	</tr>
</table>


<!-- ITEM-DROPDOWN START -->
<div class="dropdown-panel" id="dropdown-panel">
	<div class="dropdown-panel-in">
		<div class="header">
			<div style="float:left;width:110px;height:20px;">
				<table border=0>
					<tr>
						<td style="width:110px;height:20px;">品番</td>
					</tr>
				</table>
			</div>
			<div style="float:right;width:40px;text-align:right;">
				<button class="closebtn" type="button" onClick="closeBtn();" style="width:18px;height:17px; padding:0px;">
					<img src="../../common/js/dropdown/close.gif" alt="閉じる">
				</button>
			</div>
		</div>
		<div class="drop-contents" id="drop-contents">
		</div>
		<div class="footer"></div>
	</div>
</div>
<!-- ITEM-DROPDOWN END -->

</form>




</body>
</html>
